package com.app.bussinesslocator.httpclient;

import java.io.IOException;
import java.io.UnsupportedEncodingException;
import java.util.ArrayList;
import java.util.List;

import org.apache.http.HttpResponse;
import org.apache.http.client.ClientProtocolException;
import org.apache.http.client.HttpClient;
import org.apache.http.client.entity.UrlEncodedFormEntity;
import org.apache.http.client.methods.HttpPost;
import org.apache.http.impl.client.DefaultHttpClient;
import org.apache.http.message.BasicNameValuePair;

public class HttpClientMine {
	// khai bao duong dan api chung
	private static final String BASE_URL = "http://www.techbusters.net.au";
			
			
	// search
	private static final String SEARCH = "/api";
	
	HttpClient httpclient = new DefaultHttpClient();
	HttpPost httppost;

	
	void httpPost(String url){
		httppost = new HttpPost(BASE_URL+url);
	}
	
	void addParam(){
		
	}
	
	
	public void search(String keyword, int pageNumber, float lon, float lat){
		httpPost(SEARCH);
		 try {
			List<BasicNameValuePair> params = new ArrayList<BasicNameValuePair>();
			params.add(new BasicNameValuePair("keyword", keyword));
			params.add(new BasicNameValuePair("page_number", String.valueOf(pageNumber)));
			params.add(new BasicNameValuePair("latitude", String.valueOf(lat)));
			params.add(new BasicNameValuePair("longitude", String.valueOf(lon)));
			httppost.setEntity(new UrlEncodedFormEntity(params));
			
			 // Execute HTTP Post Request
	        try {
				HttpResponse response = httpclient.execute(httppost);
			} catch (ClientProtocolException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			} catch (IOException e) {
				// TODO Auto-generated catch block
				e.printStackTrace();
			}
			
		} catch (UnsupportedEncodingException e) {
			// TODO Auto-generated catch block
			e.printStackTrace();
		}
		
	}
	
}
